package java111;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;

public class Day15 {
    //https://ac.nowcoder.com/acm/problem/205350
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLong()) { // 注意 while 处理多个 case
            long x = in.nextLong();
            long left = 1;
            long right = Integer.MAX_VALUE;
            long res1 = 0, res2 = 0;
            while(left < right){
                long mid = (left + right) / 2;
                if((mid-1) * (mid-1) > x){
                    right = mid;
                } else if(mid * mid < x){
                    left = mid + 1;
                } else {
                    res1 = mid-1;
                    res2 = mid;
                    break;
                }
            }
            System.out.println(x-(res1 * res1) < (res2 * res2)-x ? res1 * res1 : res2 * res2);
        }
    }

    public static void main11(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextLong()) {
            long x = in.nextLong();
            long res1 = (long) Math.sqrt(x);
            long res2 = res1 + 1;
            long res = Math.abs(x - res1 * res1) < (res1+1) * (res1+1)-x ? res1* res1 : res2 * res2;
            System.out.println(res);
        }
    }


    //
    public static void main2(String[] args) {
        String s = "123";
        System.out.println(s.substring(0,1));
        System.out.println(s);
    }

    // https://ac.nowcoder.com/acm/problem/229023
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()){
            int n = in.nextInt();
            int m = in.nextInt();
            int[] arr = new int[n];
            HashMap<Integer, Integer> hashMap = new HashMap<>();
            HashSet<Integer> hashSet = new HashSet<>();
            int maxCount = 0;
            for(int i = 0; i < n; i++){
                arr[i] = in.nextInt();
                hashMap.put(arr[i], hashMap.getOrDefault(arr[i], 0) + 1);
                maxCount = Math.max(maxCount, hashMap.get(arr[i]));
                hashSet.add(arr[i]);
            }
            if(m < hashSet.size()){
                System.out.println(-1);
                return;
            }
            int left = 1, right = maxCount, res;
            while(left < right){
                res = 0;
                int mid = (left + right) / 2;
                for(Integer i : hashSet){
                    res += hashMap.get(i) / mid + (hashMap.get(i) % mid == 0 ? 0: 1);
                }
                if(res > m){
                    left = mid + 1;
                } else {
                    right = mid;
                }
            }
            System.out.println(left);
        }
    }
}
